// 音频自定义验证装饰器
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';

export function IsAudioFile(validationOptions?: ValidationOptions) {
  return function (object: Object, propertyName: string) {
    registerDecorator({
      name: 'isAudioFile',
      target: object.constructor,
      propertyName,
      options: validationOptions,
      validator: {
        validate(value: any, args: ValidationArguments) {
          const allowedTypes = ['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/mp4'];
          return value && value.mimetype && allowedTypes.includes(value.mimetype);
        },
        defaultMessage(args: ValidationArguments) {
          return '文件必须是音频（MP3, WAV, OGG, MP4）';
        }
      }
    });
  };
}
